# encoding=utf-8
# author:梁子龙
from fastapi import FastAPI
from fastapi.requests import Request
from starlette.responses import JSONResponse
from starlette.exceptions import HTTPException


async def http_exception_handler(request: Request, exc: HTTPException):
    return JSONResponse(status_code=exc.status_code, content={'detail': exc.detail})


def init_handler_errors(app: FastAPI):
    app.add_exception_handler(HTTPException, handler=HTTPException)
